﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using MemeSlayer.Models;

namespace MemeSlayer.Service
{
    [ServiceContract]
    public interface IMemeSlayerService
    {
        [OperationContract]
        ICollection<IMemeImage> GetAllImage();

        [OperationContract]
        IMemeImage GetImage();

        [OperationContract]
        IMemeImage GetImageById(int id);

        [OperationContract]
        ICollection<IUserModel> GetAllUsers();

        [OperationContract]
        ICollection<ITag> GetAllTags();

        [OperationContract]
        bool CheckPassword(int userId, string plainTextPassword);
    }

    [DataContract]
    public class MemeImage : IMemeImage
    {
        public string title;
        private string description;
        private string altPath;
        private string imagePath;
        private int memeImageId;
        private UserModel owner;
        private DateTime posted;
        private List<Tag> tags;

        [DataMember]
        public string AltPath
        {
            get
            {
                return altPath;
            }
            set
            {
                altPath = value;
            }
        }

        [DataMember]
        public string Description
        {
            get
            {
                return description;
            }
            set
            {
                description = value;
            }
        }

        [DataMember]
        public string ImagePath
        {
            get
            {
                return imagePath;
            }
            set
            {
                imagePath = value;
            }
        }

        [DataMember]
        public int MemeImageId
        {
            get
            {
                return memeImageId;
            }
            set
            {
                memeImageId = value;
            }
        }

        [DataMember]
        public IUserModel Owner
        {
            get
            {
                return (IUserModel)owner;
            }
            set
            {
                owner = (UserModel)value;
            }
        }

        [DataMember]
        public DateTime Posted
        {
            get
            {
                return posted;
            }
            set
            {
                posted = value;
            }
        }

        [DataMember]
        public ICollection<ITag> Tags
        {
            get
            {
                return (ICollection<ITag>)tags;
            }
            set
            {
                tags = (List<Tag>)value;
            }
        }

        [DataMember]
        public string Title
        {
            get
            {
                return title;
            }
            set
            {
                title = value;
            }
        }
    }

    [DataContract]
    public class UserModel : IUserModel
    {
        private string displayName;
        private string email;
        private int id;
        private List<MemeImage> images;
        private byte[] passhash;
        private byte permission;
        private byte[] salt;

        [DataMember]
        public string DisplayName
        {
            get
            {
                return displayName;
            }
            set
            {
                displayName = value;
            }
        }

        [DataMember]
        public string Email
        {
            get
            {
                return email;
            }
            set
            {
                email = value;
            }
        }

        [DataMember]
        public int Id
        {
            get
            {
                return id;
            }
            set
            {
                id = value;
            }
        }

        [DataMember]
        public ICollection<IMemeImage> Images
        {
            get
            {
                return (ICollection<IMemeImage>)images;
            }
            set
            {
                images = (List<MemeImage>)value;
            }
        }

        [DataMember]
        public byte[] PasswordHash
        {
            get
            {
                return passhash;
            }
            set
            {
                passhash = value;
            }
        }

        [DataMember]
        public byte PermissionLevel
        {
            get
            {
                return permission;
            }
            set
            {
                permission = value;
            }
        }

        [DataMember]
        public byte[] Salt
        {
            get
            {
                return salt;
            }
            set
            {
                salt = value;
            }
        }
    }

    [DataContract]
    public class Tag : ITag
    {
        private int tagId;
        private string tagString;

        [DataMember]
        public int TagId
        {
            get
            {
                return tagId;
            }
            set
            {
                tagId = value;
            }
        }
        
        [DataMember]
        public string TagString
        {
            get
            {
                return tagString;
            }
            set
            {
                tagString = value;
            }
        }
    }
}
